#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include "funcs.h"

extern float ratio;
extern double angle;
extern bool lights[];

void DrawTask(){
	GLfloat amb[] = {0.2f, 0.2f, 0.3f, 1.f},
			matDiffuse[] = {1.0f, 0.0f, 0.0f, 1.f},
			shining = 45,
			ambLight[] = {1.0f, 0.0f, 0.0f, 1.f},
			difL0[]={.4, .6, 1, 1},
			difL1[]={.1, .7, .3, 1},
			posL0[]={0, -.3, -.5, 0},
			posL1[]={0, 1, 0, 0};
	GLUquadricObj *quadricObj;
	quadricObj = gluNewQuadric();

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glEnable(GL_COLOR_MATERIAL);
	glMatrixMode(GL_PROJECTION);	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluPerspective(45,1/ratio,4,100);
	glTranslatef(0, 0, -5);

	gluLookAt(sin(angle * M_PI / 180), 0, cos(angle * M_PI / 180), 0, 0, 0, 0, 1, 0);

	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb);

	glLightfv (GL_LIGHT0, GL_AMBIENT, ambLight);
	glLightfv (GL_LIGHT0, GL_DIFFUSE, difL0);
	glLightfv (GL_LIGHT0, GL_SPECULAR, difL0);
	glLightfv (GL_LIGHT0, GL_POSITION, posL0);

	glLightfv (GL_LIGHT1, GL_AMBIENT, ambLight);
	glLightfv (GL_LIGHT1, GL_DIFFUSE, difL1);
	glLightfv (GL_LIGHT1, GL_SPECULAR, difL1);
	glLightfv (GL_LIGHT1, GL_POSITION, posL1);

	if (lights[0])
		glEnable(GL_LIGHT0);
	else
		glDisable(GL_LIGHT0);
	if (lights[1])
		glEnable(GL_LIGHT1);
	else
		glDisable(GL_LIGHT1);

	glPushMatrix();	
	glColor3f(1.f,1.f,1.f);
	glTranslatef(0,-.3,-.5);
	gluSphere(quadricObj, .01, 50, 50);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(0,1,0);
	gluSphere(quadricObj, .01, 50, 50);
	glPopMatrix();

	glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, matDiffuse);
	glPushMatrix ();
		glTranslatef (0.1f, 0.0f, 0.4f);
		glColor3f (0.5f, 0.1f, 0.1f);
		gluSphere (quadricObj, 0.3f, 50, 50);
	glPopMatrix ();

	glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, &shining);
	glPushMatrix ();
		glTranslatef (-.4f, -0.0f, -.4f);
		glColor3f (0.1f, 0.5f, 0.1f);
		gluSphere (quadricObj, 0.3f, 50, 50);
	glPopMatrix ();

	gluDeleteQuadric (quadricObj);

glDisable (GL_COLOR_MATERIAL);
glDisable (GL_LIGHTING);
glDisable (GL_DEPTH_TEST);
}